home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Audio / GISO / Source / StringStorage.m < prev    next >
Text File  |  1994-01-26  |  1KB  |  79 lines

  1. /*
  2. ** StringStorage.m,v 1.2 1992/11/08 13:45:25 nwc Exp
  3. **
  4. ** Copyright (c) 1991 Ronin Consulting, Inc.
  5. */
  6.  
  7.  
  8. #import "StringStorage.h"
  9. #import <string.h>
  10.  
  11. static char EOS = (char)0;
  12.  
  13. @implementation StringStorage
  14.  
  15. - init
  16. {
  17.    [self init: ""];
  18.    return self;
  19. }
  20.  
  21. - init: (const char *) str
  22. {
  23.    [super init];
  24.    
  25.    [self initCount: 0 elementSize: sizeof(char) description: "c"];
  26.    [self setStringValue: str];
  27.    return self;
  28. }
  29.  
  30. - setStringValue: (const char *) str;
  31. {
  32.    int len;
  33.  
  34.    if(!str)
  35.        str = "";                 /* avoid nil strings */
  36.  
  37.    len = strlen(str);                 /* get length - no reason to do it twice */
  38.    [self setNumSlots: len + 1];             /* use setNumSlots vs setAvailCapacity since it sets count */
  39.  
  40.                          /* bcopy is far faster than strcpy if the length is known */
  41.    bcopy(str, (char *)dataPtr, len); 
  42.    [self replaceElementAt: len with: (char *)&EOS];
  43.    return self;
  44. }
  45.  
  46. - (const char *) stringValue
  47. {
  48.    return dataPtr;
  49. }
  50.  
  51. - appendStringValue: (const char *)str
  52. {
  53.    int oldCount = [self count];
  54.    int len;
  55.  
  56.    if(!str || !*str)                 /* nothing to append */
  57.        return self;
  58.    
  59.    len = strlen(str);                 
  60.    [self setNumSlots: oldCount + len];
  61.    bcopy(str, (char *)[self elementAt: oldCount - 1], len);
  62.    [self replaceElementAt: oldCount + len -1 with: (char *)&EOS];
  63.    return self;
  64. }
  65.  
  66. - appendCharValue: (char) c
  67. {
  68.    char buf[2];
  69.    
  70.    buf[0] = c;
  71.    buf[1] = (char)0;
  72.  
  73.    [self appendStringValue: buf];
  74.  
  75.    return self;
  76. }
  77.  
  78. @end
  79.